<template>
  <div class="page">
    <div class="searchline" style="margin: 20px 0">
      <el-input
        placeholder="学生名称"
        v-model="search.name"
        size="medium"
        style="width: 200px; margin-left: 12px"
      ></el-input>
        <el-date-picker
          v-model="search.year"
          type="year"
          value-format="yyyy"
          size="medium" 
          style="width: 200px; margin-left: 12px"
        >
        </el-date-picker>
      <el-select v-model="search.major" filterable size="medium" style="width: 200px; margin-left: 12px">
          <el-option
            v-for="(item, index) in majorOption"
            :key="index"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
      <el-button
        style="margin-left: 12px"
        size="medium"
        type="primary"
        @click="searchFromList(search)"
        >筛选</el-button
      >
      <el-button size="medium" type="info" @click="reSet()">重置</el-button>
    </div>
    <el-table
      header-row-class-name="tableHeader"
      :data="list"
      border
      style="width: 98%; margin-left: 12px"
    >
      <el-table-column prop="name" label="姓名" width="150px">
      </el-table-column>
      <el-table-column prop="name" label="性别" width="150px">
        <template slot-scope="scope">
          <span>{{scope.row.Sex == 0 ? '男' : '女' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="major" label="专业" width="100px">
      </el-table-column>

      <el-table-column prop="year" label="入学年份" width="150px">
      </el-table-column>
      <el-table-column prop="gpa" label="平均绩点" width="80px">
      </el-table-column>
      <el-table-column prop="score" label="平均成绩" width="80px"> </el-table-column>
      <el-table-column prop="direction" label="求职方向" > </el-table-column>

      <el-table-column prop="empty" label="操作" width="180px">
        <template slot-scope="scope">
          <el-button
            @click="getStudentInfo(scope.row)"
            size="mini"
            type="info"
            >查看资料</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 信息弹窗 -->
    <el-dialog
      title="学生信息"
      :visible.sync="dialogVisible"
      width="35%"
      :before-close="handleClose"
    >
      <div class="dialogblock-info">
        <div class="title">{{ dialogItem.name }}</div>
        <div class="infoline">学生性别：{{ dialogItem.Sex == 0 ? '男' : '女' }}</div>
        <div class="infoline">入学年份：{{ dialogItem.year }}</div>
        <div class="infoline">专业名称：{{ dialogItem.major }}</div>
        <div class="infoline">平均成绩：{{ dialogItem.score }}</div>
        <div class="infoline">平均绩点：{{ dialogItem.gpa }}</div>
        <div class="infoline">求职方向：{{ dialogItem.direction }}</div>
        <div class="infoline">擅长技能：{{ dialogItem.skill }}</div>
        <div class="infoline">个人简介：{{ dialogItem.introduction }}</div>
        <div class="infoline">联系方式：{{ dialogItem.userPhone }}</div>
        <div class="infoline">更新时间：{{ dialogItem.updated_date }}</div>
        <div v-if="dialogItem.resume" @click="handlePictureCardPreview(dialogItem.resume)" class="infoline" style="color:rgb(65, 151, 46)">查看简历图片</div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="medium" @click="dialogVisible = false">关闭</el-button>
      </span>
    </el-dialog>
    <!-- 简历弹窗 -->
    <el-dialog :visible.sync="ImageVisible">
          <img width="100%" :src="ImageUrl" alt="" />
    </el-dialog>
  </div>
</template>
<script>
import { allStudent } from "@/api/student"
import { localData } from "@/util/local";
import { dateFormat } from "@/util/common";
import { majorOption } from "../../../util/selectOption";


export default {
  data() {
    return {
      majorOption:majorOption,
      ImageVisible:false,
      ImageUrl:"",
      value: "",
      list:[],
      initList:[],
      userInfo: {},
      dialogVisible:false,
      search: {
        name: "",
        year: "",
        major: "",
      },
      dialogItem: {
        name: "",
        year: "",
        major: "",
        score: "",
        gpa: "",
        direction: "",
        skill: "",
        introduction: "",
      },
      
    };
  },
  mounted() {
    this.userInfo = localData("get", "userinfo");
    this.getAllStudent();
  },
  methods: {
    getAllStudent() {
      allStudent().then((res) => {
        if(res.code == 200){
          this.initList = res.data.Students.map((item) => {
          item.created_date = dateFormat(
            "YYYY-mm-dd HH:MM",
            new Date(item.created_date)
          );
          item.updated_date = dateFormat(
            "YYYY-mm-dd HH:MM",
            new Date(item.updated_date)
          );
          return item;
        });
          this.list = this.initList
        }
      });
    },
    searchFromList(search) {
      const { name, year, major } = search;
      this.list = this.initList.filter((item) => {
        return (
          item.name.toString().indexOf(name.toString()) !== -1 &&
          item.year.toString().indexOf(year.toString()) !== -1 &&
          item.major.toString().indexOf(major.toString()) !== -1
        );
      });
    },
    reSet() {
      this.search = {
        name: "",
        year: "",
        major: "",
      };
      this.list = this.initList
    },
    getStudentInfo(item){
      console.log(item)
      this.dialogItem = { ...item }
      this.dialogVisible = true
    },
    handleClose() {
      this.dialogVisible = false;
      this.dialogItem = {
        name: "",
        year: "",
        major: "",
        score: "",
        gpa: "",
        direction: "",
        skill: "",
        introduction: "",
      };
    },
    handlePictureCardPreview(url){
      this.ImageUrl = url
      this.ImageVisible = true
    }
  },
};
</script>

<style scoped>
.tableHeader {
  color: rgb(65, 151, 46) !important;
}
.dialogblock-info {
  width: 100%;
  height: 60vh;
  overflow-y: auto;
}
.dialogblock-info .infoline {
  margin: 10px 0;
  font-size: 18px;
}
.dialogblock-info .title {
  margin: 15px 0;
  font-size: 24px;
  color: rgb(65, 151, 46);
  font-weight: bold;
}
</style>